#! /usr/bin/env python

import mathex

def gen(l):
    if not l:
        yield []
    else:
        for i in range(len(l)):
            for j in  gen(l[:i]+l[i+1:]):
                yield [l[i]] + j
def genwrap():
    for j in range(1,10):
        l = [i for i in range(0,10)]
        l.remove(j)
        for item in gen(l):
            yield [j] + item

def main():
    pList = [2,3,5,7,11,13,17]
    s = 0
    for i in genwrap():
        m = True
        for index,j in enumerate(pList):
            l = i[index+1:index+4]
            n = l[0]*100+l[1]*10+l[2]
            if n % j != 0:
                m = False
                break
        if m: s += reduce(lambda x,y:x*10+y,i,0)


    print s
if __name__ == '__main__':
    main()
